package cn.snorlaxzjt.LBSserver.controller;


import cn.snorlaxzjt.LBSserver.business.CommentBusiness;
import cn.snorlaxzjt.LBSserver.business.MomentBusiness;
import cn.snorlaxzjt.LBSserver.common.BusinessCode;
import cn.snorlaxzjt.LBSserver.common.Result;
import cn.snorlaxzjt.LBSserver.po.body.MomentSaveBody;
import cn.snorlaxzjt.LBSserver.po.body.MomentSelectBody;
import cn.snorlaxzjt.LBSserver.po.entity.Comment;
import cn.snorlaxzjt.LBSserver.po.page.CommentPage;
import cn.snorlaxzjt.LBSserver.po.page.MomentPage;
import cn.snorlaxzjt.LBSserver.po.page.ResultPage;
import io.swagger.annotations.Api;
import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Vector;

@RestController
@RequestMapping("/api/moment")
@Api(value = "momentController")
public class MomentController {

    @Resource
    private MomentBusiness momentBusiness;

    @Resource
    private CommentBusiness commentBusiness;

    @PostMapping("/getMyMoments")
    public Result<ResultPage<List<MomentPage>>> getMyRecord(@RequestBody MomentSelectBody body) {
        return BusinessCode.SUCCESS.toResult(momentBusiness.queryMyMoments(body));
    }

    @PostMapping("/getMomentsById")
    public Result<ResultPage<List<MomentPage>>> getMomentsById(@RequestBody MomentSelectBody body) {
        return BusinessCode.SUCCESS.toResult((momentBusiness.queryMomentsByUserId(body)));
    }

    @PostMapping("/getFriendsMoments")
    public Result<ResultPage<List<MomentPage>>> queryFriendsMoments(@RequestBody MomentSelectBody body) {
        return BusinessCode.SUCCESS.toResult((momentBusiness.queryFriendsMoments(body)));
    }

    @PostMapping("/save")
    public Result<Void> save(@RequestBody MomentSaveBody body) {
        momentBusiness.save(body);
        return BusinessCode.SUCCESS.toResult();
    }

    @PostMapping("/del")
    public Result<Void> del(Integer id) {
        momentBusiness.del(id);
        return BusinessCode.SUCCESS.toResult();
    }

    /***
     *
     * @param lon
     * @param lat
     * @param distance 公里
     * @return
     */
    @GetMapping("/queryMomentsInDis")
    public Result<ResultPage<List<MomentPage>>> queryMomentsInDis(BigDecimal lon, BigDecimal lat, Double distance){
        return BusinessCode.SUCCESS.toResult(momentBusiness.queryMomentsInDis(lon,lat,distance));
    }

    @PostMapping("/addComment")
    public Result<Void> addComment(@RequestBody Comment comment){
        return commentBusiness.save(comment);
    }

    @PostMapping("/delComment")
    public Result<Void> delComment(@Param(value = "id") Long id){
        return commentBusiness.del(id);
    }

    @GetMapping("/queryCommentByMomentId")
    public Result<List<CommentPage>> queryCommentByMomentId(@Param(value = "id") Long id){
        return commentBusiness.queryCommentByMomentId(id);
    }

}
